﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="FillCartridgeBBB.Models" %>
<%@ Import Namespace="System.Linq.Expressions" %>
<table>
        <tr>
        <%if (!ReferenceEquals(ViewData["Type"], "List"))
          {%>
            <th></th>
        <%}%>
            <th>
                Назва
            </th>
            <th>
                Адреса
            </th>
        </tr>

    <%
        //object ob = ViewData.Eval(""); 
        foreach (Department item in (IEnumerable<Department>)ViewData.Eval("Departments"))
        { 
            %>
    
        <tr>
        <%
            if (ReferenceEquals(ViewData["Type"], "Edit")) {%>
            <td>
                    
                          <%= Html.ActionLink("Edit", "Edit", new { id=item.DepartmentId }) %> |
                          <%= Html.ActionLink("Details", "Details", new { id=item.DepartmentId })%> |
                          <%= Html.ActionLink("Delete", "Delete", new { id=item.DepartmentId }, new { Onclick = "return confirm ('Ви впевнені?')"})%>
            </td>
            <%} else if (ReferenceEquals(ViewData["Type"], "Select")) {
    %>
              <td>
              <%=
                  Html.CheckBox("DepartmentId", (Model!=null) && ((Printer)Model).Departments.Where(dep => dep.DepartmentId == item.DepartmentId).Count() > 0, new Dictionary<string, object> {{"Value", item.DepartmentId}})
                  %>
              <%--<input type="checkbox" name="DepartmentId" id="DepartmetId" value="<%=item.DepartmentId %>" checked="<%=((Printer)Model).Departments.Where(dep => dep.DepartmentId == item.DepartmentId).Count() > 0 %>"/>--%>
              </td>  
            <%}
            
          if (!Equals(ViewData["Type"], "List"))
          {%>
            <td>
            <%=Html.Encode(item.Name)%>
            </td>
            <%
                }
          else
          {%>
          <td>
          <%=Html.ActionLink(item.Name, "Details", "Department",
                                                new {id = item.DepartmentId}, null)%>
                                                              </td>
                                                              <%
          }%>
            <td>
                <%= Html.Encode(item.Adress) %>
            </td>
        </tr>
    
    <% } %>

    </table>